package com.ahadu.android.walkingtime;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Play extends Activity implements SensorEventListener {
	TextView brewTimeLabel;
	TextView t;
	private boolean isWalking = false;
	private SensorManager mSensorManager;
	private Sensor mAccelerometer;



	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.play);
		brewTimeLabel = (TextView) findViewById(R.id.brew_time);
		t= (TextView) findViewById(R.id.t);
		// isWalking = false;
		mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		mAccelerometer = mSensorManager
				.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
		mSensorManager.registerListener(this, mAccelerometer,
				SensorManager.SENSOR_DELAY_NORMAL);

		// brewCountDownTimer.start();

		mSensorManager.registerListener(this, mAccelerometer,
				SensorManager.SENSOR_DELAY_NORMAL);
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// can be safely ignored for this demo
	}

	static int f = 0;
	
	@Override
	public void onSensorChanged(SensorEvent event) {

		float x = event.values[0];
		float y = event.values[1];
		float z = event.values[2];
		Log.i("Play", x + "," + y + ", " + z);

/*		if (!isWalking) {
			if ((x > 0) || (y > 0) || (z > 0)) {
				isWalking = true;
				
				
			}
			//these are the codes for counting the time
				// startBrew();
				// brewCountDownTimer.start();
				// mInitialized = true;
				// break;

			//}
		
			}
			else if ((x == 0) && (y == 0) && (z == 0)) {
				isWalking = false;
				f = 0;
				// brewCountDownTimer.onFinish();
			}
			else{
				finish();
			}
	
		
		}
	*/	
		/*
		 * if there's any acceleration at all, then the guy's walkin' 
		 * so you start your countdown
		 */
		if((x > 0) || (y > 0) || (z > 0)){
			// startBrew();
			// brewCountDownTimer.start();
			// mInitialized = true;
		}else if ((x == 0) && (y == 0) && (z == 0)){
			//stopBrew();
			//brewCountdownTimer.stop();
		}else {
			// this is the case where there's at least one negative acceleration
		}
	}
}

